Skip to content

Conversation

@AlexeyVereshchaga
Copy link

ДЗ Dagger 2

Это корень нашего дерева компонентов. Инициализируется в классе App, прокидывает в граф через Component
Dependencies/Subcomponents ниже по графу следующие сущности:
Context(Application) до ProducerFragmentComponent и ReceiverFragmentComponent. Проброс Context в граф реализуйте через BindsInstance + ComponentFactory
…Homework

# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/ru/otus/daggerhomework/App.kt
Коммуникацию между Producer и Receiver осуществите через канал/StateFlow/Subject либо другую реализацию обсервера которая уже есть в графе.
ProducerViewModel должна отправлять ивенты, ReceiverViewModel должна получать эвенты.
Обсерверы должны прокидываться в конструкторы вьюмоделей и существовать в единственном экземпляре в Activity.
@@ -0,0 +1,9 @@
package ru.otus.daggerhomework

import java.util.UUID
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется лишний импорт тут


@Component.Factory
interface Factory {
fun build(@BindsInstance context: Context): ApplicationComponent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь лучше добавить квалифайер для контекста и написать типо @ApplicationContext чтобы потом различать с контекстом активити.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И добавить метод getContext() чтобы научить ApplicationComponent отдавать его наружу

interface MainActivityComponent {
@Component.Factory
interface Factory {
fun build(@BindsInstance activity: Activity): MainActivityComponent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот здесь добавить контекст от активити c квалифайером @ActivityContext

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И добавить метод getContext() чтобы научить MainActivityComponent отдавать его наружу

interface Factory {
fun build(
mainActivityComponent: MainActivityComponent,
@BindsInstance context: Context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И здесь уже не добавлять контекст, потому что MainActivityComponent должен его предоставлять итак.

interface Factory {
fun build(
mainActivityComponent: MainActivityComponent,
@BindsInstance context: Context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь тоже самое. Контекст уже не нужно передавать. Если вы все передали через апп и активити компоненты.

* Отрефакторены компоненты
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants